function getId(goodsId) {
  let id = window.location.search.substr(1).match(new RegExp("(^|&)" + goodsId + "=([^&]*)(&|$)"))
  return id != null? unescape(id[2]):null
}
const goods = document.querySelector('.goods')
const none = document.querySelector('.none')
const gwcBox = document.querySelector('.gwc_box')
const total = document.querySelector('.total')
const content = document.querySelector('.content')
let goodsId = getId("goodsId");

let arr = JSON.parse(localStorage.getItem('goods')) || []
render()
none.style.display = 'flex'
total.style.display = 'none'
gwcBox.style.display = 'none'
content.style.display = 'none'

if (JSON.parse(localStorage.getItem('message'))) {
  total.style.display = 'flex'
  gwcBox.style.display='block'
  none.style.display = 'none'
  content.style.display = 'flex'
  if (goodsId) {
    axios.get('goods/detail', {
      params: {
        goodsId,
      }
    }).then(({ data: res }) => {
      console.log(res.data.detail)
      arr.push(res.data.detail)
      localStorage.setItem('goods', JSON.stringify(arr))
      render()
    })
  }
}

function render() {
  let str=''
  arr.forEach(item => {
    str+=`<div class="goodsbox">
    <div class="ipt"><input type="checkbox" name="" /></div>
    <div class="goodsbox_img">
      <img
        src=${item.goods_image}
        alt=""
      />
    </div>
    <div class="txt">
      <p>
       ${item.goods_name}
      </p>
      <div class="txt_price">
        <span class="pri">￥${item.goods_price_max}</span>
        <div class="txt_right">
          <span>-</span><span>1</span><span>+</span>
        </div>
      </div>
    </div>
  </div>`
  })
  document.querySelector('.goods').innerHTML = str
}

document.querySelector('.count_a i').innerHTML = arr.length == 0 ? 1 : arr.length + 1